//
//  BidJobDetailImageCollectionViewCell.swift
//  ezyform
//
//  Created by MoennigQ on 4/1/19.
//  Copyright © 2019 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SDWebImage
import SnapKit
class ServiceDetailImageCollectionViewCell: UICollectionViewCell {
    
    var imageView: UIImageView!
    let activityView = UIActivityIndicatorView()
    //28是两边的margin， 7 是item之间的间距
    static let cellSize: CGFloat = (APPConfig.WidthForPortrait - 28  * 2 - 7 * 3) / 4
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpviews()
    }
    override func  awakeFromNib() {
        super.awakeFromNib()
        setUpviews()
    }
    
    func setUpviews(){
        self.backgroundColor = UIColor.clear
        imageView = UIImageView()
        self.addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.width.height.equalTo(ServiceDetailImageCollectionViewCell.cellSize)
            make.center.equalToSuperview()
        }
    }
    func setData(_ imageUrl: String){
        self.imageView.backgroundColor = UIColor(hexStr: Constant.SystemBackColor)
        guard let url = URL(string: imageUrl) else {
            return
        }
        self.activityView.startAnimating()
        self.imageView.sd_setImage(with: url, placeholderImage: UIImage(named: "installation_detail_panelnumber_list_loadfaild"), options: [SDWebImageOptions.scaleDownLargeImages]) { image, error, cashtype, url in
            self.activityView.stopAnimating()
        }
    }
}
